<template>
  <div class="content">
    <div class="welcome-container">
      <div class="logo-container" :class="{ 'fade-in': isVisible }">
        <img
            :src="logoImage"
            alt="Voxesis Logo"
            class="app-logo"
            @click="WailsRunTime.Browser.OpenURL('https://gitee.com/Maskviva/voxesis')"
        />
      </div>

      <div class="welcome-text-container">
        <h1 class="welcome-title" :class="{ 'slide-in-top': isVisible }">
          欢迎使用 Voxesis
          <Hello :msg="msg"/>
        </h1>
        <div class="welcome-divider" :class="{ 'expand-divider': isVisible }"></div>
        <div>
          <input
              class="input"
              v-model="msgTemp"
              placeholder="输入内容"
          />
          <button class="action-button primary" style="padding: 8px" @click="msg = msgTemp">确定</button>
        </div>
      </div>

      <div class="quick-actions" :class="{ 'fade-in-delay': isVisible }">
        <button class="action-button primary" @click="AppViewMethod!.toggle_view('dashboard')">
          进入仪表板
        </button>
        <button class="action-button primary" @click="stateDialog!.show()">
          显示系统状态
        </button>
      </div>
    </div>

    <dialog ref="stateDialog">
      <span>CPU核心: {{ state.CpuCores }}</span><br/>
      <span>CPU占用: {{ state.CpuUsage.toFixed(2) }} %</span><br/>
      <span>内存占用: {{ state.MemoryUsage }} %</span><br/>
      <span>总内存: {{ state.OsMemory.toFixed(2) }} MB</span><br/>
      <button @click="stateDialog!.close()">关闭</button>
      <br/>
    </dialog>
  </div>
</template>

<script setup lang="ts">
// @ts-ignore
import {inject, onMounted, onUnmounted, ref} from 'vue';
import logoImage from '@/assets/images/logo_no_background.png';
import Hello from "@/components/Hello.vue";
import * as WailsRunTime from "WailsRunTime"
import VUtilsAPI from "VUtilsAPI"

const AppViewMethod: { toggle_view: (view: string) => void } | undefined = inject('AppViewMethod')
const isVisible = ref(false);
const msg = ref()
const msgTemp = ref()
const state = ref({
  CpuCores: 0,
  CpuUsage: 0,
  MemoryUsage: 0,
  OsMemory: 0,
})

const stateDialog = ref<HTMLDialogElement>()

onMounted(() => {
  const timeout = setTimeout(() => {
    isVisible.value = true;
  }, 100);

  const interval = setInterval(() => {
    VUtilsAPI.GetSystemState().then((res: any) => {
      state.value = res
    })
  }, 1000)

  onUnmounted(() => {
    clearInterval(interval);
    clearTimeout(timeout);
  })
});
</script>

<style scoped>.content {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  background: var(--color-background);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.welcome-container {
  width: 100%;
  max-width: 600px;
  padding: 2rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.logo-container {
  margin-bottom: 2rem;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.5s ease-out;
}

.logo-container.fade-in {
  opacity: 1;
  transform: translateY(0);
}

.welcome-text-container {
  margin-bottom: 2rem;
}

.welcome-title {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--color-text);
  margin: 0 0 1rem 0;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  opacity: 0;
  transform: translateY(30px);
  transition: all 0.5s ease-out 0.1s;
}

.welcome-title.slide-in-top {
  opacity: 1;
  transform: translateY(0);
}

.welcome-divider {
  width: 0;
  height: 10px;
  background-color: var(--color-primary);
  margin: 0 auto 1.5rem;
  border-radius: 2px;
  transition: width 0.6s ease-out 0.4s, height 0.4s ease-out 0.6s;
}

.welcome-divider.expand-divider {
  width: 50px;
  height: 3px;
}

.input {
  flex: 1;
  min-width: 0;
  height: 38px;
  padding: 0 12px;
  font-size: 14px;
  color: var(--color-text);
  background-color: var(--color-background-elevated);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-focus-ring);
}

.quick-actions {
  display: flex;
  gap: 1rem;
  margin-top: 1rem;
  opacity: 0;
  transition: opacity 0.5s ease-out 0.7s;
}

.quick-actions.fade-in-delay {
  opacity: 1;
}

.action-button {
  padding: 0.8rem 1.5rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  border: none;
  outline: none;
}

.primary {
  background-color: var(--color-primary);
  color: var(--color-text-inverse);
}

.primary:hover {
  background-color: var(--color-primary-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}

.secondary {
  background-color: var(--color-background-elevated);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.secondary:hover {
  background-color: var(--color-background-secondary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}

.app-logo {
  width: 120px;
  height: 120px;
  object-fit: contain;
  cursor: pointer;
  transition: all 0.3s ease-in-out;
}

.app-logo:hover {
  transform: rotate(360deg) scale(1.2);
}

.app-logo:active {
  transform: scale(0.9);
}

@media (max-width: 768px) {
  .welcome-container {
    padding: 1rem;
  }

  .welcome-title {
    font-size: 1.8rem;
  }

  .quick-actions {
    flex-direction: column;
    width: 100%;
    max-width: 300px;
  }

  .action-button {
    width: 100%;
  }

  .app-logo {
    width: 100px;
    height: 100px;
  }
}
</style>
